﻿using Sidvall.WorkItemManager.Workflow.WorkItems;

namespace Sidvall.WorkItemManager.UI.ViewModels.WorkItems
{
	public class TestWorkItemContextViewModel : WorkItemContextViewModel
	{
		#region Public Members

		#region WorkItemContext

		private WorkItemContext _WorkItemContext;
		public WorkItemContext WorkItemContext
		{
			get
			{
				return _WorkItemContext;
			}
			set
			{
				if (_WorkItemContext != null)
					_WorkItemContext.PropertyChanged -= OnWorkItemContextPropertyChanged;
				_WorkItemContext = value;
				if (_WorkItemContext != null)
					_WorkItemContext.PropertyChanged += OnWorkItemContextPropertyChanged;
				RaisePropertyChanged("WorkItemContext");
				OnWorkItemContextChanged();
			}
		}

		#endregion

		#region OnWorkItemContextChanged

		protected void OnWorkItemContextChanged()
		{
			this.Context = WorkItemContext.Serialize(this.WorkItemContext);
		}

		#endregion
		#region OnWorkItemContextPropertyChanged

		private void OnWorkItemContextPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
		{
			this.Context = WorkItemContext.Serialize(this.WorkItemContext);
		}

		#endregion

		#region InitializeContext

		public override void InitializeContext()
		{
			this.WorkItemContext = WorkItemContext.Deserialize(this.Context);
		}

		#endregion

		#endregion
	}
}
